package org.bao.bestmatch;

import java.util.LinkedList;

import org.bao.bestmatch.model.Matrix;
import org.bao.bestmatch.model.Module;
import org.bao.bestmatch.model.TFT_CFPair;
//import org.bao.bestmatch.utils.Configurer;

/**
 * convert Module objects into a Matrix object.
 * @author baoxiwu<bb@feijiao.info>,Cell&Module,BOE DT
 * @version 0.9.0
 * @since 2010-11-19
 * @license LGPL
 * 
 */
public class MatrixGen {
	private String path = "./file4test/SAMPLE.xls";
	
	
	public MatrixGen(){
		//empty
	}
	
	public MatrixGen(String path){
		this.path = path;
	}
	
	
	@SuppressWarnings("unchecked")
	public Matrix gen(){
		//Configurer conf = Configurer.getInstance();
		
		Matrix matrix = new Matrix();
		
		DataReader dr = new DataReader(this.path);
		
		Object[] modules = dr.crawl();
		
		LinkedList<Module> tfts = (LinkedList<Module>)modules[0];
		
		
		LinkedList<Module> cfs = (LinkedList<Module>)modules[1];
		
		//DataChecker enabled.
		/*
		if(conf.getDataCheckerEnableStatus()){
			DataChecker dc = new DataChecker();
			if(!dc.isCorrect(tfts,cfs)){
				return null;
			}
		}
		*/
		
		//set available matrix size
		matrix.setSize(tfts.size());
		TFT_CFPair pair = null;
		
		for(int i = 0; i < cfs.size(); i++){
			for(int j = 0; j < tfts.size(); j++){
				pair = new TFT_CFPair(tfts.get(j), cfs.get(i), Module.countNG(tfts.get(j), cfs.get(i)));
				matrix.add(j, i, pair);
			}
		}
		
		//System.err.println("info@MatrixGen>:\n" + matrix);
		return matrix;
	}
}
